[SECTION .data]
msg_1: db "start detecting CPU..", 10, 13, 0

format_1: db "cpu max function number : 0x%08X", 10, 13, 0

PML5_check_msg_1: db "no support PML5, continue..", 10, 13, 0
PML5_check_msg_2: db "support PML5, continue..", 10, 13, 0

old_cpu_msg: db "old cpu, end..", 10, 13, 0

no_support_x64_msg: db "no support x64, end..", 10, 13, 0
support_x64_msg: db "support x64, continue..", 10, 13, 0

cpu_info_title: db "cpu info: "
cpu_info:   times 48 db 0
cpu_info_end: db 10, 13, 0

; 保存物理地址及虚拟地址的尺寸
vir_addr_size: dd 0
max_vir_addr_size: dd 0
vir_addr_size_format: db "vir addr size : %d", 10, 13, 0
max_vir_addr_size_format: db "max vir addr size : %d", 10, 13, 0

[SECTION .text]
[BITS 32]
extern printk
global x64_cpu_check
x64_cpu_check:
    push msg_1
    call printk
    add esp, 4

.cpu_check:
    mov eax, 0x80000000
    cpuid
    cmp eax, 0x80000008
    jb .old_cpu

    push eax
    push format_1
    call printk
    add esp, 8

    mov eax, 0x80000001
    cpuid
    bt edx, 29
    jnc .no_support_x64

    push support_x64_msg
    call printk
    add esp, 4

    mov eax, 0x80000002
    cpuid
    
    mov [cpu_info], eax
    mov [cpu_info + 4], ebx
    mov [cpu_info + 8], ecx
    mov [cpu_info + 12], edx

    mov eax, 0x80000003
    cpuid
    mov [cpu_info + 16], eax
    mov [cpu_info + 20], ebx
    mov [cpu_info + 24], ecx
    mov [cpu_info + 28], edx

    mov eax, 0x80000004
    cpuid
    mov [cpu_info + 4 * 8], eax
    mov [cpu_info + 4 * 9], ebx
    mov [cpu_info + 4 * 10], ecx
    mov [cpu_info + 4 * 11], edx

    push cpu_info_title
    call printk
    add esp, 4

    push cpu_info_end
    call printk
    add esp, 4

    ret

.no_support_x64:
    push no_support_x64_msg
    call printk
    add esp, 4
    jmp .end

.old_cpu:
    push old_cpu_msg
    call printk
    add esp, 4
    jmp .end
.end:
    jmp $